package com.own.component.common.base.service.impl;

import com.own.component.common.base.entity.BaseBo;
import com.own.component.common.base.entity.BaseMap;
import com.own.component.common.base.entity.BaseQuery;
import com.own.component.common.base.entity.po.BaseBean;
import com.own.component.common.base.entity.vo.BaseBeanVo;
import com.own.component.common.base.mapper.BasePageMapper;
import com.own.component.common.base.service.BaseBindOneService;
import com.own.component.common.model.UpdateModel;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * AbstractBaseBindOneService
 *
 * @author chenxueli.0
 * @date 2020/12/24 19:05
 * @since 3.2.1
 */
@Slf4j
@Service
@SuppressWarnings("all")
public abstract class AbstractBaseBindOneService<
        PO extends BaseBean,
        BO extends BaseBo<PO>,
        VO extends BaseBeanVo<PO>,
        MAP extends BaseMap<PO>,
        QUERY extends BaseQuery,
        MAPPER extends BasePageMapper<PO, VO, MAP, QUERY>
        > extends AbstractBaseService<PO, BO, VO, MAP, QUERY, MAPPER>
        implements BaseBindOneService<PO, BO, VO, MAP, QUERY> {

    @Autowired
    private MAPPER mapper;

    /**
     * 获取绑定的数据
     *
     * @param bindId 绑定的id
     * @return 绑定标识
     */
    @Override
    public PO getPo(@NonNull Long bindId) {
        var wrapper = lambdaQueryWrapper().eq(getFkExtractor(), bindId);
        return mapper.selectOne(wrapper);
    }

    /**
     * 单个数据解绑
     *
     * @param unbindId 解绑的id
     * @return 解绑标识
     */
    @Override
    public UpdateModel<Boolean> unbind(@NonNull Long unbindId) {
        return delete(getFkExtractor(), unbindId);
    }

    /**
     * 批量数据解绑
     *
     * @param unbindIdList 解绑的id列表
     * @return 解绑标识
     */
    @Override
    public UpdateModel<Boolean> unbindBatch(@NonNull List<Long> unbindIdList) {
        return delete(getFkExtractor(), unbindIdList);
    }
}
